<?php
class CAmmember extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."am_member";
		$this->_primary = "uid";
		parent::__construct();
		
	}
	public function addCash($uid,$cash){
		$db=$this->getAdapter();
		$sql ="update ".$this->_name." set cash=cash+".$cash." where uid=".$uid;
		$result=$db->query($sql);
		return $result;
	}
	public function getUidByCode($code){
		$where = array('relatecode = ?'=>$code);
		$row = $this->fetchRow($where);
		return $row;
		
	}
	public function getDetail($uid){
		$where = array('uid = ?'=>$uid);
		$row = $this->fetchRow($where);
		return $row;
	}
	public function getUsers($page=1,$pagenum=10){
		$db = $this->getAdapter();
		$offset = ($page - 1)*$pagenum;
		$sql ="SELECT * FROM $this->_name limit $offset,$pagenum";
		$result = $db->query($sql);
		$rows = $result->fetchAll();
		return $rows;
	}
	public function getUserCount(){
		$rows = $this->fetchAll();		
		return count($rows);
	}
}